package com.wuzhuo.information.controller;

import com.wuzhuo.information.pojo.Message;
import com.wuzhuo.information.pojo.Messages;
import com.wuzhuo.information.pojo.PageBean;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wuzhuo.information.service.messageService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/message")
@Slf4j
public class messageController {

    @Autowired
    private messageService messageService;

    /**
     * 查看信息
     *
     * @param id
     * @return
     */
    @GetMapping
    public Message init(Integer id) {
        System.out.println(id);
        log.info("查看信息id:{}", id);
        Message message = messageService.getMessageById(id);
        return message;
    }

    @DeleteMapping
    public int delete(@RequestBody List<Long> ids) {
        log.info("要删除的信息id:{}", ids);
        messageService.delete(ids);
        return 1;
    }

    @GetMapping("/page")
    public List<Message> page(String addressee) {
        log.info("分页查询:{}",addressee);
        List<Message> message = messageService.page(addressee);
//        System.out.println("++++++++++++++++"+pageBean+"+++++++++++++++++++");

        return message;
    }

    @PostMapping("/reply")
    public void recover(@RequestBody Message message){
        log.info("发布信息:{}", message);
        messageService.addMessage(message);
    }

    @PostMapping("/replys")
    public void replys(@RequestBody Messages messages){
        log.info("批量回复收件人:{}",messages.getAddressee());
        messageService.replyMessages(messages);
    }

//    @PostMapping("/replyss")
//    public void replyss(@RequestBody Message message){
//        log.info("批量回复信息内容:{}",message);
//        messageService.replyMessages(message);
//    }

}
